package chapter01
/*


https://www.w3cschool.cn/groovy/groovy_loops.html

for
for in

while

break
continue


* */


class MyLoop {
    //   for loop
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            print(i + " ")
        }
        println()
    }
}


class MyLoop2 {
    public static void main(String[] args) {
        println("MyLoop2 for in Example: ")
        int[] array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
        for (int num in array) {
            print(num + " ");
        }
        println()
        loop()
        loop2()
    }

    public static void loop() {
        println("MyLoop2:loop for in Example: ")
        // 包含两个端点 0-9 闭区间
        for (int i in 0..9) {
            print(i + " ")
        }
        println()
    }

    public static void loop2() {
        def users = ["Key": 21, "frank": 18, "tom": 22, "colin": 19]
        for (user in users) {
            println(user)
//            print(user.toString()+" ")
        }
        println()
    }
}


class MyLoop3 {
    /*
    while
    */

    public static void main(String[] args) {
        int count = 0;
        int maxCount = 10;
        while (count < maxCount) {
            println("count:${count}")
            count++;
        }
        println()
    }
}


class MyLoop4 {
    /*
    while
    */

    public static void main(String[] args) {
        int count = 0;
        int maxCount = 100;
        int breakValue = 10;
        while (count < maxCount) {
            println("count:${count}")
            count++;
            if (count >= breakValue) {
                println("count:${count},breakValue:${breakValue}, break")
                break;
            }
        }
        println()
        break2()

    }

    public static void break2() {
        println("============= break2 begin ===========")
        for (int i = 0; i < 10; i++) {
            if (i == 5) {
                println("i==5,break")
                break;
            }
            print(i + " ");
        }
    }
}